<?php

namespace Zhutong;
//use \Exception\InputException;

class SMS
{

	public static $_templates = [
		'vcode' => '您的短信验证码为：%04d（5分钟内有效），此验证码用于登录或注册，请勿向他人泄露。【捎货】',
	];

	//短信验证码
	public static function sendCaptcha($phone, $code, $smsType = 0, $template = 'vcode')
	{
		if ($smsType == 1) {
			$sendRes = Zhutong::getInstance()->sendVoiceSMs($phone, $code);
		} else {
			$content = sprintf(self::$_templates[$template], $code);
			$sendRes = Zhutong::getInstance()->sendSingleSms($phone, $content);
		}
		return $sendRes;
	}

	//批量营销短信
	public static function sendBatchSms($phones, $content)
	{
		return $res = Zhutong::getInstance()->sendBatchSms($phones, $content);
	}

	//自定义短信发送
	public static function sendCustomSms($phone, $tpl, $args)
	{
		$tpls = &\SmsParam::$_sms_tpl;
//		if (!isset($tpls[$tpl])) {
//				throw new InputException(EC::TPL_ILLEGAL);
//		}
//		\log::info('=========' . var_export($args, true));
//		\log::info('=========' . var_export($tpl, true));
		$content = str_replace(array_map(function($item){ return '{{' . $item . '}}'; }, array_keys($args)), array_values($args), $tpls[$tpl]);

		$content .= "【捎货】";

		return Zhutong::getInstance()->sendSingleSms($phone, $content);
	}
}


?>